var passport = require('passport');
var BasicStrategy = require('passport-http').BasicStrategy;
var models=require('../models/models');

/*
 * 前台在请求头里 Authorization  Basic 用户名+冒号+密码"用BASE64算法加密后的字符串
 */

module.exports = (passport) => { 
  var verify = (username, password, done) => {
    let md5 = require('crypto').createHash('md5')
    let passwordmd5=md5.update(password).digest('hex')
    models.getModel('mysqlmodel').getAdminByPassword(username,passwordmd5)
          .then(result=>result[0]===undefined?done(null,false):done(null,result[0]))
          .catch(err=>done(err,false))
  }
  passport.use(new BasicStrategy(verify))
}